

export const formatTime = (date: Date, contact = '.') => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return (
    [year, month, day].map(formatNumber).join(contact) +
    ' ' +
    [hour, minute, second].map(formatNumber).join(':')
  )
}

const formatNumber = (n: number) => {
  const s = n.toString()
  return s[1] ? s : '0' + s
}


export const getWeek = (date: Date = new Date) => {
  var weeks = new Array(
    "星期日",
    "星期一",
    "星期二",
    "星期三",
    "星期四",
    "星期五",
    "星期六"
  )
  return weeks[date.getDay()]
}

// 提取富文本文本
export const dealContent = (str: string = "",aliOssUrlPath='') => {
  return str
    .replace(/(<!--.*?-->)/g, '')//清除注释
    .replace(/src="{path}/g, `src="${aliOssUrlPath}`)//添加img Baseurl
    .replace(/\<p/gi, '<p class="p_class"')//p标签添加class
    .replace(/\<div/gi, '<div class="p_class"')//div标签添加class
    .replace(/\<span/gi, '<div class="p_class"')//div标签添加class
    .replace(/\<h/gi, '<h1 class="h_class"')//h1标签添加class
    .replace(/\<img/gi, '<img class="img_class"')//img标签添加class
}
